Skip to content

Replace PAT with github login - #8

Merged
jellebuning merged 6 commits into
mainfrom
issues/3-replace-pat-with-github-login
Nov 3, 2026
Merged

jellebuning merged 6 commits into
mainfrom
issues/3-replace-pat-with-github-login

Conversation

@jellebuning

Copy link
Copy Markdown
Member

Summary

The personal access token sign-in is replaced by signing in with a GitHub account through the OAuth device flow. The user gets a short code, approves it on github.com, and the app receives an access token without any password or token being typed or any client secret shipped.

What changed

  • New sign-in flow in Kontext.GitHub (GitHubDeviceLogin, response parsing in DeviceFlowResponses): requests a device code, polls for the token with the interval GitHub returns (handles pending, slow down, expiry, denial and cancellation), only talks to github.com/login/device/code and github.com/login/oauth/access_token, and only accepts an https github.com verification link. New contract IGitHubDeviceLogin and record DeviceCodeChallenge.
  • ShellViewModel: the token field is gone; signing in shows the code and the verification link, can be cancelled, and signing out cancels a pending sign-in. The token is saved only after GitHub has accepted it.
  • Sign-in screen: the token box and the "create a token" link are replaced by a "Sign in with GitHub" button, the device code panel and a Cancel button.
  • Token storage: the access token is stored in the existing Windows Credential Locker entry under a new name, and a previously saved personal access token is deleted on the next start, so existing users sign in once with GitHub.
  • The OAuth App client id (not a secret) is read from the environment variable KONTEXT_GITHUB_CLIENT_ID. Without it, the sign-in screen shows a clear "not configured" message. README updated (requirements and a Configuration section).

Before this works end to end

  1. Register a GitHub OAuth App at github.com/settings/developers and tick "Enable Device Flow" (no client secret or callback URL needed).
  2. Set KONTEXT_GITHUB_CLIENT_ID to its client id and restart Kontext.
  3. Organisations that restrict OAuth apps must approve the app, which is different from a personal access token.
    Signing out only forgets the token locally; the grant can be revoked in GitHub settings.

Testing

  • dotnet build Kontext.slnx -c Release: 0 warnings, 0 errors.
  • dotnet test Kontext.slnx -c Release: all projects passed (GitHub 77, Presentation 203, Architecture 27, Composition 19, GitAutomation 111, and the rest). 71 new tests cover the response parsing and the flow with a stubbed HTTP handler and a fake clock (polling, slow down, expiry, denial, cancellation, errors, URI validation, no token in error messages), and 15 new view model tests replace the three removed token tests.
  • Not run: the real device flow against github.com (needs a registered OAuth App), the Credential Locker migration (a leftover saved token is deleted and the user is asked to sign in again), the sign-in screen rendering with the Cancel and open-link buttons, and the environment variable wiring in the app project. These have no automated tests in this repo.

Closes #3

Sign in with the GitHub account through the OAuth device flow instead of
pasting a personal access token. The access token is stored in the existing
credential store, and a previously saved token is removed. The OAuth App
client id is read from KONTEXT_GITHUB_CLIENT_ID.
@jellebuning

Copy link
Copy Markdown
Member Author

Cut down the file size, take SOLID and KISS in mind

Move the HTTP transport into GitHubFormPoster and the token result types into their own file, so GitHubDeviceLogin only holds the flow.
Split the large device login and shell view model test files by responsibility and drop duplicated cases. Behaviour is unchanged.
@jellebuning

Copy link
Copy Markdown
Member Author

Split the device login code and tests into smaller files. The HTTP transport now lives in GitHubFormPoster and the token result types have their own file, so GitHubDeviceLogin only holds the flow (118 to 69 lines). The 519-line device login test file is split into a shared base, Start tests and Wait tests, and the shell view model tests into a fixture, the main tests and the sign-in tests. Duplicated test cases were removed or merged; behaviour and messages are unchanged. Build and the full test suite pass.

@jellebuning
jellebuning merged commit d13e3ce into main Nov 3, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace PAT with github login

1 participant